package FlyWeight;

public class FlyWeightPatternDemo {

    private static final String colors[] = {"Red", "Green", "Blue", "White", "Black"};

    public static void main(String[] args) {
        for (int i = 1; i < 20; i++) {
            Circle circle = (Circle) ShapeFactory.getCircle(getRandomColor());

            circle.setRadius(100);
            circle.setY(getRandomY());
            circle.setX(getRandomX());

            circle.draw();

        }

    }


    public static String getRandomColor(){
        return colors[(int) ( Math.random() * colors.length)];
    }

    public static int getRandomX(){
        return (int) (Math.random()*100) ;  // 注意后面的括号
    }

    public static int getRandomY(){
        return (int) (Math.random()*100);
    }
}
